﻿using BinaryFormatter_的简单使用;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace BinaryFormatter_的简单使用
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string path = @"D:\test\config\config.txt";
            using(FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate))
            {
                User user = new User();
                user.Name = "张三";
                user.Password = "159753";
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(fileStream, user);
            }
            using(FileStream fileStream = new FileStream(path, FileMode.Open))
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                object obj = binaryFormatter.Deserialize(fileStream);
                User user = obj as User;
                Console.WriteLine(user.Name);
                Console.WriteLine(user.Password);
            }
        } 
    }
}
